package com.ilxqx.fierce;

import com.ilxqx.fierce.core.FierceRequest;
import com.ilxqx.fierce.core.FierceResponse;
import com.ilxqx.fierce.core.RequestHandlerDelegate;
import lombok.RequiredArgsConstructor;
import org.springframework.context.ApplicationContext;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 请求总调度器
 *
 * @author Venus
 * @since 1.0.0
 */
@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
public class FierceDispatcher {

    private final ApplicationContext applicationContext;

    /**
     * 统一调度请求
     *
     * @return 结果对象
     */
    @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    public FierceResponse dispatch(@RequestBody FierceRequest request) {
        return RequestHandlerDelegate.handleRequest(request, this.applicationContext);
    }
}
